home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 16 / AMIGAplus Sonderheft 16 (1998)(ICP)(DE)[!].iso / pd / anwendungen / xpk_source / xpkmaster / debug.c < prev    next >
C/C++ Source or Header  |  1998-08-27  |  3KB  |  140 lines

  1. #ifndef XPKMASTER_DEBUG_C
  2. #define XPKMASTER_DEBUG_C
  3.  
  4. /* Routinesheader
  5.  
  6.     Name:        debug.c
  7.     Main:        xpkmaster
  8.     Versionstring:    $VER: debug.c 1.8 (25.06.1998)
  9.     Author:        SDI
  10.     Distribution:    Freeware
  11.     Description:    the debug stuff
  12.  
  13.  1.0   05.10.96 : first real version
  14.  1.1   20.10.96 : added the external debug modes
  15.  1.2   21.10.96 : changed debug totally
  16.  1.3   01.01.97 : changed output a bit - "XpkM before stuff - find in lots
  17.      of other debuf stuff"
  18.  1.4   09.03.97 : output contained 0 byte - removed
  19.  1.5   01.04.97 : little changes
  20.  1.6   12.04.97 : added TagList output, therefor changed XPKDEBUG contents
  21.  1.7   21.02.98 : uses new style register definition
  22.  1.8   25.06.98 : now uses SDI_compiler.h
  23. */
  24.  
  25. #include <exec/types.h>
  26. #include <proto/exec.h>
  27. #include <proto/dos.h>
  28. #include <proto/utility.h>
  29. #include <utility/tagitem.h>
  30. #include <dos/var.h>
  31. #include <xpk/xpk.h>
  32. #include "xpkmaster.h"
  33. #include "SDI_compiler.h"
  34.  
  35. typedef void (*putchtype) ();
  36.  
  37. #define FLAG_ERROR    (1<<0)
  38. #define FLAG_RUNTIME    (1<<1)
  39. #define FLAG_TAGLIST    (1<<2)
  40.  
  41. extern LONG STDARGS KPutChar(LONG);
  42. extern LONG STDARGS DPutChar(LONG);
  43. extern void DoDebug(UBYTE mode, STRPTR fmt, APTR data);
  44.  
  45. static ASM(void) serfunc(REG(d0, UBYTE c), REG(a3, ULONG pd))
  46. { if(c) KPutChar(c); }
  47.  
  48. static ASM(void) parfunc(REG(d0, UBYTE c), REG(a3, ULONG pd))
  49. { if(c) DPutChar(c); }
  50.  
  51. static ASM(void) normfunc(REG(d0, UBYTE c), REG(a3, ULONG pd))
  52. {
  53.   UBYTE d = c;
  54.   if(c)
  55.     Write(pd, &d, 1);
  56. }
  57.  
  58. void DebugTagList(STRPTR fmt, struct TagItem *taglist)
  59. {
  60.   DoDebug(FLAG_TAGLIST, fmt, taglist);
  61. }
  62.  
  63. void DebugError(STRPTR format, ...)
  64. {
  65.   DoDebug(FLAG_RUNTIME, format, (APTR)((ULONG)(&format)+sizeof(STRPTR)));
  66. }
  67.  
  68. void DebugRunTime(STRPTR format, ...)
  69. {
  70.   DoDebug(FLAG_ERROR, format, (APTR)((ULONG)(&format)+sizeof(STRPTR)));
  71. }
  72.  
  73. void DoDebug(UBYTE mode, STRPTR fmt, APTR data)
  74. {
  75.   ULONG fh = 0, i, Flags = 0;
  76.   UBYTE Mode[5] = "";
  77.   ASM(void) (*function)(REG(d0, UBYTE), REG(a3, ULONG)) = 0;
  78.  
  79.   Forbid();
  80.  
  81.   GetVar("XPKDEBUG", (STRPTR) &Mode, 5, GVF_GLOBAL_ONLY);
  82.  
  83.   for(i=1; Mode[i] && i < 5; ++i)
  84.   {
  85.     switch(Mode[i])
  86.     {
  87.       case 'E': Flags |= FLAG_ERROR; break;
  88.       case 'R': Flags |= FLAG_RUNTIME; break;
  89.       case 'T': Flags |= FLAG_TAGLIST; break;
  90.     }
  91.   }
  92.  
  93.   mode &= Flags;
  94.  
  95.   if(mode)
  96.   {
  97.     switch(Mode[0])
  98.     {
  99.     case 'S': function = serfunc; break;
  100.     case 'P': function = parfunc; break;
  101.     case 'F':
  102.       if((fh = Open("T:XpkMasterOut", MODE_READWRITE)))
  103.       {
  104.         Seek(fh, 0, OFFSET_END);
  105.         function = normfunc;
  106.       }
  107.       break;
  108.     }
  109.     if(function)
  110.     {
  111.       i = (ULONG) FindTask(0);
  112.       RawDoFmt("XpkM(%08lx):", &i, (putchtype) function, (APTR) fh);
  113.  
  114.       RawDoFmt(fmt, data, (putchtype) function, (APTR) fh);
  115.       RawDoFmt("\n", 0, (putchtype) function, (APTR) fh);
  116.  
  117.       if(mode & FLAG_TAGLIST)
  118.       {
  119.         struct TagItem *ti;
  120.         while((ti = NextTagItem((struct TagItem **) &data)))
  121.         {
  122.           RawDoFmt("   %08lx, %lu", ti, (putchtype) function, (APTR) fh);
  123.           if((ti->ti_Tag == XPK_InName) || (ti->ti_Tag == XPK_OutName) ||
  124.           (ti->ti_Tag == XPK_FileName) || (ti->ti_Tag == XPK_Password) ||
  125.           (ti->ti_Tag == XPK_PackMethod))
  126.             RawDoFmt(" (%s)", &ti->ti_Data, (putchtype) function, (APTR) fh);
  127.           RawDoFmt("\n", 0, (putchtype) function, (APTR) fh);
  128.         }
  129.       }
  130.     }
  131.  
  132.     if(fh)
  133.       Close(fh);
  134.   }
  135.  
  136.   Permit();
  137. }
  138.  
  139. #endif /* XPKMASTER_DEBUG_C */
  140.